package com.sdkx.app.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.sdkx.app.R;
import com.sdkx.app.activitys.MainActivity;
import com.sdkx.app.adapter.MainMenuAdapter;
import com.sdkx.app.util.PixelUtil;

public class MapLayerFragment extends BaseFragment implements View.OnClickListener {
    private ListView lvGroup;
    private RecyclerView recyclerView;
    LayerAdapter layerAdapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_menu_map11, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.findViewById(R.id.tv_all_air_spaces2).setOnClickListener(this);
        recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        layerAdapter = new LayerAdapter();
        recyclerView.setAdapter(layerAdapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_all_air_spaces2:
                goBack();
                break;
        }
    }
    protected  class LayerAdapter extends RecyclerView.Adapter<LayerAdapter.ViewHolder>{
        String[] arrays =  getResources().getStringArray(R.array.maplayers);
        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new ViewHolder(getLayoutInflater().inflate(R.layout.airspace_item,null));
        }

        @Override
        public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
            holder.init(arrays[position]);
        }

        @Override
        public int getItemCount() {
            return arrays.length;
        }

        public class ViewHolder extends RecyclerView.ViewHolder{
            CheckBox checkBox;
            TextView name;
            ImageView arrow;
            public ViewHolder(View itemView) {
                super(itemView);
                itemView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,70));
                checkBox = itemView.findViewById(R.id.checkid);
                int  pxDimension = (int )TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, 50,getResources().getDisplayMetrics());
                checkBox.setWidth( pxDimension);
                checkBox.setHeight(pxDimension);
                name = itemView.findViewById(R.id.name);
                arrow = itemView.findViewById(R.id.next);
                arrow.setVisibility(View.GONE);
                checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                    }
                });
            }
            public void init(String text){
                name.setText(text);
            }
        }
    }

}